<meta charset="utf-8" />
<form action="">
  <hr />
  用户名：
  <input type="text" id="uname" />
  <br />
  <br />
  <hr />
  密&nbsp&nbsp&nbsp码：
  <input type="password" id="pwd" />
  <br />
  <br />
  <input type="checkbox" id="checkbox" value="没勾选" />
  勾选七天免登录
  <hr />
  <img src="http://kg.zhaodashen.cn/v1/public/captcha.jsp" alt="" />
  <br />
  <br />
  验证码:
  <input type="text" name="" id="captcha" />
  <hr />
  <button type="submit">提交</button>
</form>
<script src="./axios.js"></script>
<!-- 实现点击切换验证码 -->
<script>
  document.querySelector("img").onclick = function () {
    document.querySelector("img").src =
      "http://kg.zhaodashen.cn/v1/public/captcha.jsp";
  };
</script>
<script>
  document.querySelector("button").onclick = async function (ev) {
    let e = ev || window.event;
    e.preventDefault();
    let uname = document.querySelector("#uname").value;
    let pwd = document.querySelector("#pwd").value;
    let captcha = document.querySelector("#captcha").value;
    let check = document.querySelector("#checkbox");
    let res = await post("http://kg.zhaodashen.cn/v1/public/login.jsp", {
      uname,
      pwd,
      captcha,
    });
    if (res.meta.state === 200) {
      if (check.checked) {
        localStorage.setItem("uname", res.data.uname);
        localStorage.setItem("expires", new Date().getTime() + 1000 * 20);
      } else {
        sessionStorage.setItem("uname", res.data.uname);
      }
      location.href = "./member.html";
    } else {
      alert(res.meta.msg);
    }
  };
</script>
